package com.idc.excel.cr;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class RulesUtil {

	private static Set<String> zxsSet = new HashSet<>(Arrays.asList("北京", "天津", "上海", "重庆"));

	private static Set<String> specialSet = new HashSet<>();

	static {

	}

	public static void fixData(CrData crData) {
		// 如果包含地市，一定包含省份
		if ("是".equals(crData.getIsContainCityKey())) {
			crData.setIsContainProKey("是");
		}
		// 逻辑口检查和非业务口检查只有有一个是，前面项置为\
		if (crData.isLogicNotBusCheck()) {
			setToNull(crData);
		} else if (specialSet.contains(crData.getCircuitProperties())) {
			setToNull(crData);
		}
		crData.reloadCompliance();
		if (!crData.isCompliance()) {
			if (crData.getDeviceName().endsWith("163") && crData.getDeviceIp().startsWith("202.97.3")) {
				crData.setIsCompliance("合规");
				crData.setRemark("骨干设备下联端口");
			}
			if (zxsSet.contains(crData.getProvinceName())) {
				crData.setIsContainProKey("\\");
				crData.setIsContainCityKey("\\");
				crData.setRemark("直辖市下联端口暂不核查省份地市关键字");
				crData.reloadCompliance();
				if (!crData.isCompliance()) {
					if ("是".equals(crData.getBusPortCheck()) && crData.isBusUserCompliance()) {
						if (crData.getCircuitProperties().contains("下联") || crData.getCircuitProperties().contains("自用口")) {
							crData.setIsCompliance("合规");
							crData.setRemark("直辖市下联端口暂不核查省份地市关键字，下联平台端口，无法获取对端设备端口信息，暂定合规");
						}
					} else if ("是".equals(crData.getUserPortCheck()) && crData.isBusUserCompliance()) {
						if (crData.getCircuitProperties().contains("下联") || crData.getCircuitProperties().contains("自用口")) {
							crData.setIsCompliance("合规");
							crData.setRemark("直辖市下联端口暂不核查省份地市关键字，下联用户端口，无法获取对端设备端口信息，暂定合规");
						}
					}
				}
			} else {
				if ("是".equals(crData.getBusPortCheck()) && crData.isBusUserCompliance()) {
					crData.setIsCompliance("合规");
					crData.setRemark("下联平台端口，无法获取对端设备端口信息，暂定合规");
				} else if ("是".equals(crData.getUserPortCheck()) && crData.isBusUserCompliance()) {
					crData.setIsCompliance("合规");
					crData.setRemark("下联用户端口，无法获取对端设备端口信息，暂定合规");
				}
			}
		}
	}

	private static void setToNull(CrData crData) {
		crData.setIsUpDownLink("\\");
		crData.setIsContainProKey("\\");
		crData.setIsContainCityKey("\\");
		crData.setIsContainNetBusKey("\\");
		crData.setIsContainDeviceKey("\\");
		crData.setIsContainBandwidthKey("\\");
		crData.setIsContainPortKey("\\");
	}
}
